home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / util / pack / xpk_Source.lha / xpk_Source / xpkmaster / libdata.a < prev    next >
Text File  |  1996-11-26  |  8KB  |  321 lines

  1. * Routinesheader
  2. *
  3. *    Name:        libdata.a
  4. *    Main:        xpkmaster
  5. *    Versionstring:    $VER: libdata.a 3.11 (25.11.96)
  6. *    Author:        SDI
  7. *    Distribution:    PD
  8. *    Description:    all the library startup data
  9. *
  10. * 3.10  28.10.96 : first real version
  11. * 3.11  25.11.95 : recompiled with SAS 6.57
  12.  
  13.     NOLIST
  14.     INCLUDE    "AINCLUDE:IncDirs.i" *sets all includedirs, needed for my ASM
  15.     INCLUDE "exec/types.i"
  16.     INCLUDE "exec/initializers.i"
  17.     INCLUDE "exec/libraries.i"
  18.     INCLUDE "exec/lists.i"
  19.     INCLUDE "exec/alerts.i"
  20.     INCLUDE "exec/resident.i"
  21.     INCLUDE "dos/dos.i"
  22.     INCLUDE    "lvo.i"
  23.     LIST
  24.  
  25. *_SysBase    EQU    4
  26. *        XDEF    _SysBase
  27.  
  28. VERSION        EQU    3
  29. REVISION    EQU    11
  30. MINOSVERSION    EQU    0
  31.  
  32. STRINGANZ    EQU    12
  33. STRINGSTART    EQU    0
  34. ERRSTRINGANZ    EQU    33
  35. ERRSTRINGSTART    EQU    200
  36.  
  37. VSTRING    MACRO
  38.         DC.B    'xpkmaster 3.11 (25.11.96)',13,10,0
  39.     ENDM
  40.  
  41. ;    XDEF    InitTable
  42. ;    XDEF    Open
  43. ;    XDEF    Close
  44. ;    XDEF    Expunge
  45. ;    XDEF    Null
  46. ;    XDEF    LibName
  47.     XDEF    _DOSBase,_DosBase,_IntuitionBase,_UtilityBase
  48.     XDEF    _MainVersion
  49.  
  50.     XREF    _XpkExamine,_XpkPack
  51.     XREF    _XpkUnpack,_XpkOpen,_XpkRead,_XpkWrite
  52.     XREF    _XpkSeek,_XpkClose,_XpkQuery
  53.     XREF    _strings,_XpkErrs
  54.  
  55.     SECTION    "XPK_LibStart",Code
  56. Start    MOVEQ    #-1,d0    ; return an error in case someone
  57.     RTS        ; tried to run as a program
  58.  
  59. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  60. ; discover magic constants about you (such as where to start running you
  61. ; from...).
  62.  
  63. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  64.         DC.L    RomTag        ; APTR  rt_MatchTag
  65.         DC.L    ENDCODE        ; APTR  rt_EndSkip
  66.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  67. _MainVersion    DC.B    VERSION        ; UBYTE rt_Version
  68.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  69.         DC.B    0        ; BYTE  rt_Pri
  70.         DC.L    LibName        ; APTR  rt_Name
  71.         DC.L    IDString    ; APTR  rt_IDString
  72.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  73.  
  74. LibName        DC.B    'xpkmaster.library',0
  75. DOSNAME        DC.B    'dos.library',0
  76. INTUITIONNAME    DC.B    'intuition.library',0
  77. UTILITYNAME    DC.B    'utility.library',0
  78. LOCALENAME    DC.B    'locale.library',0
  79. CATALOGNAME    DC.B    'xpkmaster.catalog',0
  80.         CNOP    0,2
  81. IDString    VSTRING
  82.           CNOP    0,2    ; word alignement
  83.  
  84. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  85. ; rt_Init structure member points to one of these tables below. If the
  86. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  87.  
  88. InitTable:
  89.     DC.L    LIB_SIZE        ; size of library base data space
  90.     DC.L    funcTable        ; pointer to function initializers
  91.     DC.L    dataTable        ; pointer to data initializers
  92.     DC.L    initRoutine        ; routine to run
  93.  
  94. funcTable:
  95. ;------ standard system routines
  96.     DC.L    Open
  97.     DC.L    Close
  98.     DC.L    Expunge
  99.     DC.L    Null
  100. ;------ my libraries definitions
  101.     DC.L    Null
  102.     DC.L    _XpkExamine
  103.     DC.L    _XpkPack
  104.     DC.L    _XpkUnpack
  105.     DC.L    _XpkOpen
  106.     DC.L    _XpkRead
  107.     DC.L    _XpkWrite
  108.     DC.L    _XpkSeek
  109.     DC.L    _XpkClose
  110.     DC.L    _XpkQuery
  111. ;------ function table end marker
  112.     DC.L    -1
  113.  
  114. ; The data table initializes static data structures. The format is specified
  115. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  116. ; routines are in the file "exec/initializers.i". The first argument is the
  117. ; offset from the library base for this byte/word/long. The second argument
  118. ; is the value to put in that cell. The table is null terminated.
  119.  
  120. dataTable:
  121.     INITBYTE    LN_TYPE,NT_LIBRARY
  122.     INITLONG    LN_NAME,LibName
  123.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  124.     INITWORD    LIB_VERSION,VERSION
  125.     INITWORD    LIB_REVISION,REVISION
  126.     INITLONG    LIB_IDSTRING,IDString
  127.     DC.L        0
  128.  
  129. ; This routine gets called after the library has been allocated. The library
  130. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  131. ; the library will be linked into the library list.
  132.  
  133. initRoutine:
  134. ;------ get the library pointer into a convenient A register
  135.     MOVEM.L    A2/D6/D7/A6/A5,-(A7)
  136.     MOVEA.L    D0,A5
  137. ;------ save a pointer to our loaded code
  138.     MOVE.L    A0,SegList
  139. ;
  140. ; specific openings here
  141. ;
  142.     MOVEA.L    4.W,A6
  143.     MOVEQ    #MINOSVERSION,D0
  144.     LEA    DOSNAME(PC),A1
  145.     JSR    _LVOOpenLibrary(A6)
  146.     MOVE.L    D0,_DOSBase
  147.     BEQ.B    .kill
  148.     MOVEQ    #MINOSVERSION,D0
  149.     LEA    INTUITIONNAME(PC),A1
  150.     JSR    _LVOOpenLibrary(A6)
  151.     MOVE.L    D0,_IntuitionBase
  152.     BEQ.B    .kill
  153.     MOVEQ    #MINOSVERSION,D0
  154.     LEA    UTILITYNAME(PC),A1
  155.     JSR    _LVOOpenLibrary(A6)
  156.     MOVE.L    D0,_UtilityBase
  157. *    BEQ.B    .kill            * remove mark out, when special
  158.                     * OS 2.0 version
  159.     MOVEQ    #38,D0
  160.     LEA    LOCALENAME(PC),A1
  161.     JSR    _LVOOpenLibrary(A6)
  162.     MOVE.L    D0,_LocaleBase
  163.     BEQ.B    .endok
  164.     MOVEA.L    D0,A6
  165.     SUBA.L    A0,A0
  166.     JSR    _LVOOpenLocale(A6)
  167.     MOVE.L    D0,_Locale
  168.     BEQ.B    .endok
  169.     MOVEA.L    D0,A0
  170.     LEA    CATALOGNAME(PC),A1
  171.     SUBA.L    A2,A2
  172.     JSR    _LVOOpenCatalogA(A6)
  173.     MOVE.L    D0,_Catalog
  174.     BEQ.B    .endok
  175.     MOVEQ    #STRINGANZ-1,D6
  176.     MOVEQ    #STRINGSTART,D7
  177.     LEA    _strings,A2
  178.     BSR.B    DoLocale
  179.     MOVEQ    #ERRSTRINGANZ-1,D6
  180.     MOVE.L    #ERRSTRINGSTART,D7
  181.     LEA    _XpkErrs,A2
  182.     BSR.B    DoLocale
  183.  
  184. .endok    MOVE.L    A5,D0
  185. .end    MOVEM.L    (A7)+,A2/D6/D7/A6/A5
  186.     RTS
  187. .kill    BSR.B    KillLibs
  188.     MOVEQ    #0,D0
  189.     BRA.B    .end
  190.  
  191. DoLocale    MOVE.L    _Catalog(PC),A0
  192.         MOVE.L    D7,D0
  193.         MOVEA.L    A2,A1
  194.         ADDQ.L    #1,D7
  195.         JSR    _LVOGetCatalogStr(A6)
  196.         MOVE.L    D0,(A2)+
  197.         DBRA.B    D6,DoLocale
  198.         RTS
  199.  
  200. ; here begins the system interface commands. When the user calls
  201. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  202. ; into a call to the following routines (Open/Close/Expunge). Exec has
  203. ; already put our library pointer in A6 for us. Exec has turned off task
  204. ; switching while in these routines (via Forbid/Permit), so we should not
  205. ; take too long in them.
  206.  
  207. ; Open returns the library pointer in D0 if the open was successful. If the
  208. ; open failed then null is returned. It might fail if we allocated memory
  209. ; on each open, or if only one application could have the library open at
  210. ; a time...
  211.  
  212. Open:        ; (libptr:A6, version:D0)
  213. ;------ mark us as having another opener
  214.     ADDQ.W    #1,LIB_OPENCNT(A6)
  215.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  216.     MOVE.L    A6,D0
  217.     RTS
  218.  
  219. ; There are two different things that might be returned from the Close
  220. ; routine. If the library is no longer open and there is a delayed expunge
  221. ; then Close should return the segment list (as given to Init). Otherwise
  222. ; close should return NULL.
  223.  
  224. Close:        ; (libptr:A6)
  225. ;------ set the return value
  226.     MOVEQ    #0,D0
  227. ;------ mark us as having one fewer openers
  228.     SUBQ.W   #1,LIB_OPENCNT(A6)
  229. ;------ see if there is anyone left with us open
  230.     BNE.B    .OneLeft
  231. ;------ do the expunge
  232.     BTST    #LIBB_DELEXP,LIB_FLAGS(a6)
  233.     BEQ.B    .OneLeft
  234.     BSR.B    Expunge
  235. .OneLeft
  236.     RTS
  237.  
  238. ; There are two different things that might be returned from the Expunge
  239. ; routine. If the library is no longer open then Expunge should return the
  240. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  241. ; expunge flag and return NULL.
  242. ; One other important note: because Expunge is called from the memory
  243. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  244.  
  245. Expunge:    ; (libptr: A6)
  246.     MOVEM.L    D2/A5/A6,-(A7)
  247.     MOVEA.L    A6,A5
  248.     MOVEA.L    4.W,A6
  249. ;------ see if anyone has us open
  250.     TST.W    LIB_OPENCNT(A5)
  251.     BEQ.B    .DoIt
  252.     BSET    #LIBB_DELEXP,LIB_FLAGS(A6)
  253.     MOVEQ    #0,D0
  254.     BRA.B    .Expunge_End
  255. .DoIt
  256. ;------ go ahead and get rid of us.  Store our seglist in D2
  257.     MOVE.L    SegList(PC),D2
  258. ;------ unlink from library list
  259.     MOVEA.L    A5,A1
  260.     JSR    _LVORemove(A6)
  261. ;
  262. ; device specific closings here...
  263.     BSR.B    KillLibs
  264. ;
  265. ;------ free our memory
  266.     MOVEQ    #0,D0
  267.     MOVEA.L    A5,A1
  268.     MOVE.W    LIB_NEGSIZE(A5),D0
  269.     SUBA.L    D0,A1
  270.     ADD.W    LIB_POSSIZE(A5),D0
  271.     JSR    _LVOFreeMem(A6)
  272. ;------ set up our return value
  273.     MOVE.L    D2,D0
  274.  
  275. .Expunge_End
  276.     MOVEM.L    (A7)+,D2/A5/A6
  277.     RTS
  278.  
  279. KillLibs:    MOVEA.L    4.W,A6
  280.         MOVEA.L    _IntuitionBase(PC),A1
  281.         MOVE.L    A1,D0                ; for checking
  282.         BEQ.B    .utility
  283.         JSR    _LVOCloseLibrary(A6)
  284. .utility    MOVEA.L    _UtilityBase(PC),A1
  285.         MOVE.L    A1,D0
  286.         BEQ.B    .dos
  287.         JSR    _LVOCloseLibrary(A6)
  288. .dos        MOVEA.L    _DOSBase(PC),A1
  289.         MOVE.L    A1,D0
  290.         BEQ.B    .locale
  291.         JSR    _LVOCloseLibrary(A6)
  292. .locale        MOVEA.L    _LocaleBase(PC),A6
  293.         MOVE.L    A1,D0
  294.         BEQ.B    .endlibs
  295.         MOVEA.L    _Catalog(PC),A0
  296.         MOVE.L    A0,D0
  297.         BEQ.B    .closelocale
  298.         JSR    _LVOCloseCatalog(A6)
  299. .closelocale    MOVEA.L    _Locale(PC),A0
  300.         MOVE.L    A0,D0
  301.         BEQ.B    .closelibrary
  302.         JSR    _LVOCloseLocale(A6)
  303. .closelibrary    MOVEA.L    A6,A1
  304.         MOVEA.L    4.W,A6
  305.         JSR    _LVOCloseLibrary(A6)
  306. .endlibs    RTS
  307.  
  308. Null:    MOVEQ    #0,D0
  309.     RTS
  310.  
  311. SegList:    DC.L    0    * set by Init
  312. _Catalog:    DC.L    0
  313. _Locale:    DC.L    0
  314. _LocaleBase:    DC.L    0
  315. _DosBase:
  316. _DOSBase:    DC.L    0    * set by Init    these are library globals
  317. _UtilityBase:    DC.L    0    * set by Init    in C Code read only !!!
  318. ENDCODE:
  319. _IntuitionBase:    DC.L    0    * set by Init
  320.         END
  321.